Skip to content

Canvas fit: decouple logical from physical dimensions (closes #17) - #63

Merged
dabd merged 5 commits into
mainfrom
fix/decouple-dimensions
Oct 7, 2025
Merged

Canvas fit: decouple logical from physical dimensions (closes #17)#63
dabd merged 5 commits into
mainfrom
fix/decouple-dimensions

Conversation

@dabd

@dabd dabd commented Oct 3, 2025

Copy link
Copy Markdown
Collaborator

Testing

  • Vite sandbox
    • Build: ./mill sandbox.fastLinkJS
    • Dev: cd sandbox && yarn install && yarn dev
    • Preview (prod): yarn build && yarn preview
    • Open the URL.
  • Tyrian sandbox
    • Build: ./mill sandbox-tyrian.fastLinkJS
    • Dev: cd sandbox-tyrian && yarn install && yarn dev
    • Preview (prod): yarn build && yarn preview
  • Verification
    • Edit sandbox/index.html:21 to width="600" height="200" (or width="1300" height="300").
    • With renderToFit, chart fills canvas without cropping; with renderTo, it crops or doesn’t fill.
    • Same check in Tyrian: adjust canvas in sandbox-tyrian/src/florence/sandbox/TyrianSandbox.scala,
      switch renderToFit to renderTo in sandbox-tyrian/src/florence/sandbox/CustomChart.scala.

Known limitations

Legend overlap on small canvases: renderToResize redraws without distortion but does not auto-
reserve space for the legend. On short canvases (e.g., 600x200 shown below) the legend can overlap the plot.
Temporary workarounds: move legend to Top/Bottom, reduce legend font/symbol size, or increase margins.
See issue #64 for details.

  • Screenshots

600x200:
Screenshot 2025-10-03 at 21 16 29

1300x300:
Screenshot 2025-10-03 at 21 16 53

…pdate sandboxes, flake.nix cleanup, add .envrc (closes #17)
@davesmith00047

Copy link
Copy Markdown
Collaborator

@dabd I haven't looked at the code properly (I can look at this properly on Monday if you like), but I have run the tyrian version. At the moment the result is that the output is stretched or squashed somehow, where presumably what we want is to redraw it cleanly at the requested size, no?
image

@dabd

dabd commented Oct 3, 2025

Copy link
Copy Markdown
Collaborator Author

@dabd I haven't looked at the code properly (I can look at this properly on Monday if you like), but I have run the tyrian version. At the moment the result is that the output is stretched or squashed somehow, where presumably what we want is to redraw it cleanly at the requested size, no? image

That is right, currently I am scaling X and Y independently to match the canvas.
I will look at improving to recompute layout for the target size without distortion.

@dabd
dabd force-pushed the fix/decouple-dimensions branch 2 times, most recently from bdfa79e to ef935f7 Compare October 3, 2025 20:28
…esize, keep renderToFit for non-uniform fill, flake.nix add git to dev shell
@dabd
dabd force-pushed the fix/decouple-dimensions branch from ef935f7 to 71e1bcd Compare October 3, 2025 20:29
@dabd

dabd commented Oct 3, 2025

Copy link
Copy Markdown
Collaborator Author

@davesmith00047 Pushed an improvement in 71e1bcd and created issue #64 to solve a separate problem that is apparent in this PR: charts in small canvases can show overlapping legends.

Comment thread flake.nix
let
pkgs = import nixpkgs { inherit system; };
jdkToUse = pkgs.jdk17;
sbtWithJRE = pkgs.sbt.override { jre = jdkToUse; };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed sbt since we are not using it

Comment thread flake.nix
pkgs.git
pkgs.nodejs
pkgs.yarn
pkgs.nodePackages_latest.http-server

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unused package

@davesmith00047

Copy link
Copy Markdown
Collaborator

Looks good!
image

@davesmith00047 davesmith00047 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I have just one small request around the render method naming / docs.


extension [C <: Chart, S <: ChartStyle](styled: StyledChart[C, S])

def renderToFit(ctx: CanvasRenderingContext2D)(using

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add scaladoc's to these? It isn't clear to me from the naming, or a glance at the code, what these different rendering modes do.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 50aa023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm still not sure what the use case is for renderFillCanvas, but it's doing no harm, no reason not to live with it for a while and see how it pans out. 🙂

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let's keep it lean.

The intention was for renderFillCanvas to scale the already laid-out drawing independently in X and Y to fill the canvas (but this could warp elements). Can't think of a very compelling use case 🤔 , - maybe draw small things like spark lines, or lots of thumbnails quickly.

renderAtCanvasSize recomputes layout for the new size, avoiding this warping, so I will just keep this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified in b19c328

…asWith for non-uniform fill, renderAtCanvasSize and renderAtCanvasSizeWith for redraw
davesmith00047
davesmith00047 previously approved these changes Oct 7, 2025
@dabd
dabd merged commit 65b1c24 into main Oct 7, 2025
1 check passed
@dabd
dabd deleted the fix/decouple-dimensions branch October 7, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants